﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

namespace VirtualTournaments.Frontend.MenuControls.GenericControls
{
    using Team = Services.Tournaments.Team;
    using TeamsService = Services.Tournaments.TeamsService;
    using PlayersService = Services.Tournaments.PlayersService;
    using Player = Services.Tournaments.Player;

    public partial class TeamInfo : System.Web.UI.UserControl
    {
        public string TeamName
        {
            get 
            {
                return TeamNameLabel.Text;
            }
            set 
            {
                TeamNameLabel.Text = value;
            }
        }

        public ListBox TeamPlayersList
        {
            get 
            {
                return TeamPlayersListBox;
            }
            set 
            {
                TeamPlayersListBox = value;
            }
        }

        public Table TeamPlayersTable
        {
            get 
            {
                return teamPlayersTable;
            }
            set 
            {
                teamPlayersTable = value;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            Player[] playersInTeam = PlayersService.GetPlayersByTeamName(TeamName);

            TableRow row;
            TableCell cell;
            foreach (Player player in playersInTeam)
            {
                row = new TableRow();
                this.TeamPlayersList.Items.Add(new ListItem(player.Name));

                cell = new TableCell();
                cell.Text = player.Name;
                cell.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                row.Cells.Add(cell);

                cell = new TableCell();
                cell.Text = player.Role;
                cell.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                row.Cells.Add(cell);

                foreach (string ability in player.Abilities)
                {
                    cell = new TableCell();
                    cell.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                    cell.Text = ability;
                    row.Cells.Add(cell);
                }
                this.TeamPlayersTable.Rows.Add(row);
            }
        }
    }
}